﻿Module modGIS
    Public Sub Main()
        ShowGIS()
        'ShowGMap()
    End Sub

    <System.ComponentModel.Composition.Export("Shell", GetType(ContainerControl))>
    Private Shell As ContainerControl

    Public GISForm As WRDB.GIS.frmGIS

    Public Sub ShowGIS()
        Try

            System.Windows.Forms.Application.EnableVisualStyles()
            GISForm = New WRDB.GIS.frmGIS(WRDB.GIS.frmGIS.enumMode.Animate)
            With GISForm
                'note: for the DotSpatial AppManager to work correctly, by trial and error it was determined that it must be initialized in the caller
                Shell = GISForm
                'Dim GISAppManager As New DotSpatial.Controls.AppManager
                'With GISAppManager
                '    .Directories.Clear()
                '    .Directories.Add("Plugins")
                '    .Directories.Add("Application Extensions")
                '    .ShowExtensionsDialog = DotSpatial.Controls.ShowExtensionsDialog.None 
                '    .Map = GISForm.GISMap
                '    .Legend = GISForm.GISLegend
                '    .SerializationManager = New DotSpatial.Controls.SerializationManager(GISAppManager)
                '    .LoadExtensions()
                'End With

                If My.Application.CommandLineArgs.Count = 0 Then
                    .ShowDialog()
                Else
                    Dim cmdLine As String = My.Application.CommandLineArgs(0).Replace("""", "")
                    If cmdLine.ToUpper.Replace("/", "-") = "-L" Then
                        .LoadLast = True
                        .ShowDialog()
                    ElseIf My.Computer.FileSystem.FileExists(cmdLine.Replace("""", "")) Then
                        .LoadFile = cmdLine.Replace("""", "")
                        .ShowDialog()
                    Else
                        MessageBox.Show("WRDBGIS usage:\n\t-L or /L\t= load last map\n\tFilename\t= load specified .gis file on startup (enclose in quotes if path contains spaces)".Replace("\n", vbCr).Replace("\t", vbTab), "WRDBGIS", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End If
                End If
                .Dispose()
            End With


        Catch ex As Exception

            MessageBox.Show("The following error occurred in the application:" & vbCr & vbCr & ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Public Sub ShowGMap()
        'With New WRDB.GIS.frmGMap(Nothing)
        '    .ShowDialog()
        'End With
    End Sub
End Module
